﻿using System.Windows.Controls;
using System.Windows.Input;

namespace StockAnalyst2
{
	internal partial class MainToolBar : UserControl
	{
		#region Properties

		public new MainToolBarVM DataContext
		{
			get
			{
				return (MainToolBarVM)base.DataContext;
			}
			set
			{
				if (this.DataContext != value)
				{
					base.DataContext = value;
				}
			}
		}

		#endregion

		#region Public Methods

		public MainToolBar()
		{
			InitializeComponent();
		}

		#endregion

		#region Event Handlers

		private void DatePicker_CalendarOpened(object sender, System.Windows.RoutedEventArgs e)
		{
			if (this.DataContext.ApplicationCommandsVM.RefreshAvailableDaysCommand.CanExecute(null))
			{
				this.DataContext.ApplicationCommandsVM.RefreshAvailableDaysCommand.Execute(null);	
			}
		}

		private void DatePickerChart_CalendarOpened(object sender, System.Windows.RoutedEventArgs e)
		{
			if (this.DataContext.ChartToolBarVM.ChartCommandsVM.RefreshAvailableDaysCommand.CanExecute(null))
			{
				this.DataContext.ChartToolBarVM.ChartCommandsVM.RefreshAvailableDaysCommand.Execute(null);	
			}
		}

		private void TextBox_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
		{
			if (e.Key == Key.Enter && this.DataContext.ApplicationCommandsVM.ApplyNameFilterCommand.CanExecute(null))
			{
				this.DataContext.ApplicationCommandsVM.ApplyNameFilterCommand.Execute(null);
			}
		}

		private void ComboBox_DropDownOpened(object sender, System.EventArgs e)
		{
			if (this.DataContext.ChartToolBarVM.ChartCommandsVM.RefreshStocksAvailableCommand.CanExecute(null))
			{
				this.DataContext.ChartToolBarVM.ChartCommandsVM.RefreshStocksAvailableCommand.Execute(null);
			}
		}

		#endregion
	}
}
